While insertion and deletion required $O(n)$ time due to mandatory traversal to a specific index $i$, searching for an item requires a similar linear approach.

  • To locate a node containing a specific target value (x), we must perform a sequential comparison starting from the head of the list.
  • This search operation is known as a linear search in the context of linked lists.
  • We use a pointer, $p$, to iterate through each node until a match is found or the list terminates ($\text{NULL}$).
  • The process involves checking the current node, and if no match, moving to the next node via the pointer.

Complexity Analysis: Find an Item

Time Complexity: $O(n)$

In the worst-case scenario, we must visit all $n$ nodes (if the item is at the end or not present).

Space Complexity: $O(1)$

Fixed space is used only for the temporary pointer $p$.

Key Takeaway: Unlike arrays where random access can locate an item in $O(1)$ if the index is known, linked lists must be traversed linearly to find either a position or a value.